﻿using System;
using System.Collections.Generic;
using System.Text;
using TntOrm;
using TntOrm.Attributes;

namespace SiteObjects
{
    [OrmTable( "WEB_Post", "Сообщения", true )]
    public class Post : OrmDataBaseObject
    {
        private int? id_Post;

        [OrmTableField( "id_Post", System.Data.SqlDbType.Int, false )]
        [OrmPrimaryKey]
        public int? PostID
        {
            get { return id_Post; }
            set { id_Post = value; }
        }

        private User _User;

        [OrmTableField( "id_User", System.Data.SqlDbType.Int, false )]
        [OrmLookUp]
        [OrmReference( typeof( User ), "UserID", BelongType.HasOne )]
        public User User
        {
            get { return _User; }
            set { _User = value; }
        }

        private Photo[] _Photo;

        [OrmCrossReference( "PostToPhoto", typeof( PostPhoto ), typeof( Photo ), "id_Photo", "id_Post" )]
        public Photo[] Photos
        {
            get 
            {
                if( _Photo == null )
                {
                    _Photo = GetCrossData<Photo>( "PostToPhoto" );
                }

                return _Photo; 
            }
            set { _Photo = value; }
        }

        private string _Name;

        [OrmTableField( "Name", System.Data.SqlDbType.NVarChar, 200, false )]
        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        private string _NameEng;

        [OrmTableField( "NameEng", System.Data.SqlDbType.NVarChar, 200, false )]
        public string NameEng
        {
            get { return _NameEng; }
            set { _NameEng = value; }
        }

        private string _UrlName;

        [OrmTableField( "UrlName", System.Data.SqlDbType.VarChar, 100, false )]
        [OrmLookUp]
        public string UrlName
        {
            get { return _UrlName; }
            set { _UrlName = value; }
        }

        private string _Text;

        [OrmTableField( "Text", System.Data.SqlDbType.NText, true )]
        public string Text
        {
            get { return _Text; }
            set { _Text = value; }
        }

        private string _TextEng;

        [OrmTableField( "TextEng", System.Data.SqlDbType.NText, true )]
        public string TextEng
        {
            get { return _TextEng; }
            set { _TextEng = value; }
        }

        private string _Keywords;

        [OrmTableField( "Keywords", System.Data.SqlDbType.NText, true )]
        public string Keywords
        {
            get { return _Keywords; }
            set { _Keywords = value; }
        }

        private string _Description;

        [OrmTableField( "Description", System.Data.SqlDbType.NText, true )]
        public string Description
        {
            get { return _Description; }
            set { _Description = value; }
        }

        private string _XML;

        [OrmTableField( "XML", System.Data.SqlDbType.NText, true )]
        public string XML
        {
            get { return _XML; }
            set { _XML = value; }
        }

        #region Deleted, approved, DateCreated
        private bool? _Deleted;

        [OrmTableField( "Deleted", System.Data.SqlDbType.Bit, true)]
        [OrmLookUp]
        public bool? Deleted
        {
            get { return _Deleted; }
            set { _Deleted = value; }
        }

        private bool? _Approved;

        [OrmTableField( "Approved", System.Data.SqlDbType.Bit, true )]
        [OrmLookUp]
        public bool? Approved
        {
            get { return _Approved; }
            set { _Approved = value; }
        }

        private DateTime? _DateCreated;

        [OrmTableField( "DateCreated", System.Data.SqlDbType.DateTime, -1, false, "getdate()" )]
        public DateTime? DateCreated
        {
            get { return _DateCreated; }
            set { _DateCreated = value; }
        }
        #endregion
        
        private DateTime? _DateApproved;

        [OrmTableField( "DateApproved", System.Data.SqlDbType.DateTime, -1, true )]
        public DateTime? DateApproved
        {
            get { return _DateApproved; }
            set { _DateApproved = value; }
        }

        private DateTime? _PublishDate;

        [OrmTableField( "PublishDate", System.Data.SqlDbType.DateTime, -1, true )]
        public DateTime? PublishDate
        {
            get { return _PublishDate; }
            set { _PublishDate = value; }
        }
    }
}